<script setup lang="ts">
import { onMounted, Ref, ref } from 'vue'
import {
  Menu,
  Message,
  FormInstance,
  RequestOption,
  UploadRequest,
  FileItem,
  Table,
  TableColumnData
} from '@arco-design/web-vue'
import { IconSettings, IconUser, IconHistory } from '@arco-design/web-vue/es/icon'
import { useUserStore } from '@/store'
import LoginLog from './loginLog.vue'
import Account from './account.vue'
import Information from './information.vue'

const activeKey = ref('account')

// 菜单项列表
const menuItems = [
  {
    key: 'account',
    title: '账号设置',
    icon: IconSettings
  },
  {
    key: 'profile',
    title: '个人资料',
    icon: IconUser
  },
  {
    key: 'logs',
    title: '访问日志',
    icon: IconHistory
  }
]
</script>

<template>
  <div class="settings-container">
    <!-- 顶部菜单 -->
    <div class="settings-header">
      <a-menu
        mode="horizontal"
        :selected-keys="[activeKey]"
        @menu-item-click="(key) => (activeKey = key)"
      >
        <a-menu-item v-for="item in menuItems" :key="item.key">
          <template #icon>
            <component :is="item.icon" />
          </template>
          {{ item.title }}
        </a-menu-item>
      </a-menu>
    </div>

    <!-- 内容区域 -->
    <div class="settings-content">
      <!-- 账号设置 -->
      <div v-show="activeKey === 'account'" class="settings-section">
        <Account />
      </div>

      <!-- 个人资料 -->
      <div v-show="activeKey === 'profile'" class="settings-section">
        <Information />
      </div>

      <!-- 访问日志 -->
      <div v-show="activeKey === 'logs'" class="settings-section">
        <LoginLog />
      </div>
    </div>
  </div>
</template>

<style scoped>
.settings-container {
  height: 100%;
  background-color: var(--color-bg-1);
}

.settings-header {
  border-bottom: 1px solid var(--color-border);
  background-color: var(--color-bg-2);
}

:deep(.arco-menu) {
  background: transparent;
}

:deep(.arco-menu-horizontal) {
  border-bottom: none;
}

:deep(.arco-menu-item) {
  margin: 0 20px;
  padding: 0 16px;
  font-size: 14px;
  height: 44px;
  line-height: 44px;
}

.settings-content {
  padding: 20px;
  max-width: 900px;
  margin: 0 auto;
}

.section-item {
  background-color: #fff;
  border-radius: 4px;
  margin-bottom: 16px;
}

.item-header {
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text-1);
  border-bottom: 1px solid var(--color-border);
}

.item-content {
  padding: 0 20px;
}

.info-row {
  display: flex;
  padding: 16px 0;
  border-bottom: 1px solid var(--color-border);
}

.info-row:last-child {
  border-bottom: none;
}

.info-label {
  width: 80px;
  font-size: 14px;
  color: var(--color-text-2);
  line-height: 32px;
}

.info-value {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.input-area {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.value-text {
  font-size: 14px;
  color: var(--color-text-1);
}

.empty-text {
  font-size: 14px;
  color: var(--color-text-3);
}

.info-tip {
  font-size: 13px;
  color: var(--color-text-3);
  width: 120px;
  text-align: right;
  flex-shrink: 0;
}

:deep(.arco-form-item) {
  margin-bottom: 0;
}

:deep(.arco-form-item-layout-horizontal) {
  display: flex;
  align-items: center;
}

:deep(.arco-form-item-label-col) {
  width: 80px;
  text-align: right;
  padding-right: 12px;
}

:deep(.arco-form-item-wrapper) {
  flex: 1;
  min-width: 0;
  width: 240px;
}

.form-actions {
  padding-left: 80px;
  display: flex;
  justify-content: center;
  width: 320px;
  margin-top: 16px;
  margin-left: 0;
}

:deep(.arco-btn-size-small) {
  font-size: 13px;
  padding: 0 12px;
  height: 28px;
}

.bind-input-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.action-buttons {
  display: flex;
  gap: 8px;
  height: 32px;
  align-items: center;
}

:deep(.arco-input-wrapper) {
  width: 240px;
}

:deep(.arco-space) {
  margin-left: 8px;
}

.avatar-upload {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.avatar-wrapper {
  width: 160px;
  height: 160px;
  border: 1px dashed var(--color-border);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  overflow: hidden;
}

.avatar-wrapper:hover {
  border-color: rgb(var(--primary-6));
  background: var(--color-fill-2);
}

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--color-text-3);
}

.avatar-placeholder .arco-icon {
  font-size: 24px;
}

.upload-tip {
  font-size: 13px;
  color: var(--color-text-3);
}

:deep(.arco-input-tag) {
  width: 240px;
}

.log-table {
  margin: -16px -20px; /* 抵消父容器的内边距 */
}

:deep(.arco-table-th) {
  background-color: var(--color-bg-2) !important;
  font-weight: 500;
  color: var(--color-text-1);
}

:deep(.arco-table-tr) {
  cursor: default;
}

:deep(.arco-table-td) {
  color: var(--color-text-2);
}

:deep(.arco-table-hover-cell) {
  background-color: var(--color-fill-2) !important;
}
</style>
